package com.whosly.fast.web.quickly.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 自定义额外的静态资源路径
 * <p>
 *
 * Folders:
 * +----- resources
 *   --------- r
 *      +--------- who.html
 *   --------- static
 *      +--------- favicon.ico
 *      +--------- js/canvas.js
 *   --------- templates
 *      +--------- 404.html
 *      +--------- index.html
 *
 * <p>
 *
 * Links:
 *    http://localhost:18080/r/who.html
 *    http://localhost:18080/favicon.ico
 *    http://localhost:18080/js/canvas.js
 *    http://localhost:18080/index.html
 *    http://localhost:18080/404.html
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 请注意下面这个映射，将资源路径 /r 下的资源，映射到根目录为 /r 的访问路径下
        // 如 r 下的 who.html, 对应的访问路径为  r/who.html
        registry.addResourceHandler("/r/**")
                .addResourceLocations("classpath:/r/");
//                .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS));
    }

}
